// 引入路由
import { asyncRouter, constantRoutes } from '@/router'
const state = {
  routers: []
}

const mutations = {
  setRouter(store, data) {
    store.routers = [
      ...constantRoutes,
      ...data
    ]
  }
}

const actions = {
  // 设置过滤函数
  filterRouter(store, menu) {
    // 当asyncRouter的name属性在menu中，就是我们需要的页面
    const router = asyncRouter.filter(router => {
      return menu.includes(router.name)
    })
    store.commit('setRouter', router)
    console.log('过滤后的路由', router)
    return router
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
